package top.kaoshanji.p1ch02e.main;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import top.kaoshanji.p1ch02e.config.ProjectConfig;

import java.util.function.Supplier;

/**
 * 代码清单-p1ch02e-41页a：使用registerBean()方法向Spring上下文添加一个bean
 * @author kaoshanji
 * ^_^
 * create time 2025/4/27 16:46
 */
public class Main {

    public static void main(String[] args) {

        var context = new AnnotationConfigApplicationContext(ProjectConfig.class);

        Parrot parrot = new Parrot();
        parrot.setName("Kiki");

        Supplier<Parrot> parrotSupplier = () -> parrot;

        context.registerBean("parrot1", Parrot.class, parrotSupplier, bc -> bc.setPrimary(true));

        Parrot p = context.getBean(Parrot.class);
        System.out.println(p.getName());

    }

}
